package com.taobao.server.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.taobao.dao.ReceiveDao;
import com.taobao.pojo.Receive;
import com.taobao.pojo.Task;
import com.taobao.server.CommonServer;
import com.taobao.server.TookingServer;

public class TookingServerImpl extends CommonServer implements TookingServer {

    private ReceiveDao receiveDao;

    @Override
    public Map<String, List<Task>> getPublishTasksIng() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Map<String, List<Task>> getReceiveTasksIng() {
        Map<String, List<Task>> receiveMap = new HashMap<String, List<Task>>();
        receiveMap.put(Receive.INPUTSMALLER, new ArrayList<Task>());
        receiveMap.put(Receive.PAY, new ArrayList<Task>());
        receiveMap.put(Receive.SENT, new ArrayList<Task>());
        receiveMap.put(Receive.RECEIVE, new ArrayList<Task>());
        receiveMap.put(Receive.CONFIRM, new ArrayList<Task>());
        receiveMap.put(Receive.ALL, new ArrayList<Task>());

        try {
            List<Task> tasks = receiveDao.getReceiveTasksIng();
            for (Task task : tasks) {
                String state = task.getState().getState() + "";
                if (Receive.INPUTSMALLER.equals(state)) {
                    List<Task> tList = receiveMap.get(Receive.INPUTSMALLER);
                    tList.add(task);
                }
                if (Receive.PAY.equals(state)) {
                    List<Task> tList = receiveMap.get(Receive.PAY);
                    tList.add(task);
                }
                if (Receive.SENT.equals(state)) {
                    List<Task> tList = receiveMap.get(Receive.SENT);
                    tList.add(task);
                }
                if (Receive.RECEIVE.equals(state) || Receive.RECEIVE_TIMEOUT.equals(state)) {
                    List<Task> tList = receiveMap.get(Receive.RECEIVE);
                    tList.add(task);
                }
                if (Receive.CONFIRM.equals(state)) {
                    List<Task> tList = receiveMap.get(Receive.CONFIRM);
                    tList.add(task);
                }

                List<Task> tList = receiveMap.get(Receive.ALL);
                Task newTask = task.clone();
                tList.add(newTask);

            }
        } catch (Exception e) {
            e.printStackTrace();
            receiveMap = null;
        }
        return receiveMap;
    }

}
